--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_hijiri_byakuren = General:new(extension, "hy_hijiri_byakuren", "ten_k", 3, 3, General.Female)
    local unusual_buddhism = fk.CreateSkill {
        name = "unusual_buddhism",
    }
    unusual_buddhism:addEffect(fk.TargetSpecified, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(self) and #player:getCardIds("h") < player:getMaxCards() and data.from ~= player and data.to == player
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:drawCards(player, 2, unusual_buddhism.name)
            if #player:getCardIds("he") > 0 then
                local card = room:askToCards(player, {
                    min_num = 1,
                    max_num = 1,
                    include_equip = true,
                    skill_name = unusual_buddhism.name,
                    cancelable = false,
                    prompt = "unusual_buddhism_prompt"
                })
                if type(card) == "number" then
                    card = { card }
                end
                room:moveCardTo(card, Card.DrawPile, nil, fk.ReasonPut, unusual_buddhism.name, nil, nil, player)
            end
        end,
    })
    local perform_sacrament = fk.CreateSkill {
        name = "perform_sacrament",
    }
    perform_sacrament:addEffect("active", {
        target_num = 1,
        card_num = 0,
        target_filter = function(self, player, to_select, selected, selected_cards)
            return #selected == 0 and to_select ~= player
        end,
        card_filter = Util.FalseFunc,
        can_use = function(self, player)
            return player:usedSkillTimes(perform_sacrament.name, Player.HistoryPhase) < 1 and #player:getCardIds("h") > 0
        end,
        prompt = "perform_sacrament_prompt",
        on_use = function(self, room, cardUseEvent)
            local player = cardUseEvent.from
            local target = cardUseEvent.tos[1]
            room:moveCardTo(player:getCardIds("h"), Card.PlayerHand, target, fk.ReasonGive, perform_sacrament.name, nil, true, player, "@@perform_sacrament-inhand")
            local marks = player:getTableMark("perform_sacrament")
            table.insertIfNeed(marks, target.id)
            room:setPlayerMark(player, "perform_sacrament", marks)
        end,
    })
    perform_sacrament:addEffect(fk.EventPhaseEnd, {
        can_trigger = function(self, event, target, player, data)
            local marks = player:getTableMark("perform_sacrament")
            local record = table.contains(player:getTableMark("perform_sacrament"), target.id)
            if target.phase == Player.Play and record then
                table.removeOne(marks, target.id)
                player.room:setPlayerMark(player, "perform_sacrament", marks)
                return not player.dead and
                    (target:getMark("perform_sacrament_lose") > 0 or table.any(target:getTableMark("perform_sacrament_use"), function(trueName)
                        return player:canUse(Fk:cloneCard(trueName), { bypass_times = true })
                    end))
            end
        end,
        on_cost = function(self, event, target, player, data)
            local choices = {}
            table.insertTableIfNeed(choices, table.filter(target:getTableMark("perform_sacrament_use"), function(trueName)
                return player:canUse(Fk:cloneCard(trueName), { bypass_times = true })
            end))
            if target:getMark("perform_sacrament_lose") > 0 then
                table.insertIfNeed(choices, "perform_sacrament_draw:::" .. tostring(target:getMark("perform_sacrament_lose")))
            end
            table.insertIfNeed(choices, "Cancel")
            event:setCostData(self, player.room:askToChoice(player, {
                choices = choices,
                skill_name = perform_sacrament.name,
                prompt = "perform_sacrament_prompt_choice"
            }))
            return event:getCostData(self) ~= "Cancel"
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if event:getCostData(self) == "perform_sacrament_draw:::" .. tostring(target:getMark("perform_sacrament_lose")) then
                local count = target:getMark("perform_sacrament_lose")
                room:drawCards(player, 1, perform_sacrament.name)
                room:addPlayerMark(player, MarkEnum.AddMaxCards, count)
            else
                room:askToUseVirtualCard(player, {
                    name = event:getCostData(self),
                    skill_name = perform_sacrament.name,
                    prompt = "perform_sacrament_prompt_use:::" .. event:getCostData(self),
                    cancelable = false,
                    extra_data = {
                        bypass_times = true,
                    }
                })
                local choices = {}
                for _, name in pairs(target:getTableMark("perform_sacrament_use")) do
                    if Fk:cloneCard(name).type ~= Fk:cloneCard(event:getCostData(self)).type and player:canUse(Fk:cloneCard(name), { bypass_times = true }) then
                        table.insertIfNeed(choices, name)
                    end
                end
                if #choices > 0 then
                    table.insertIfNeed(choices, "Cancel")
                    local result = player.room:askToChoice(player, {
                        choices = choices,
                        skill_name = perform_sacrament.name,
                        prompt = "perform_sacrament_prompt_choice"
                    })
                    if result ~= "Cancel" then
                        room:askToUseVirtualCard(player, {
                            name = result,
                            skill_name = perform_sacrament.name,
                            prompt = "perform_sacrament_prompt_use:::" .. result,
                            cancelable = false,
                            extra_data = {
                                bypass_times = true,
                            }
                        })
                    end
                end
            end
        end,
    })
    perform_sacrament:addEffect(fk.EventPhaseStart, {
        can_refresh = function(self, event, target, player, data)
            return target.phase == Player.Play and table.contains(player:getTableMark("perform_sacrament"), target.id)
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            room:setPlayerMark(target, "perform_sacrament_lose", 0)
            room:setPlayerMark(target, "perform_sacrament_use", {})
        end
    })
    perform_sacrament:addEffect(fk.CardUseFinished, {
        can_refresh = function(self, event, target, player, data)
            return target.phase == Player.Play and table.contains(player:getTableMark("perform_sacrament"), target.id)
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            if data.card.type == Card.TypeBasic or data.card:isCommonTrick() then
                local marks = target:getTableMark("perform_sacrament_use")
                table.insertIfNeed(marks, data.card.name)
                room:setPlayerMark(target, "perform_sacrament_use", marks)
            end
        end
    })
    perform_sacrament:addEffect(fk.EventPhaseEnd, {
        can_refresh = function(self, event, target, player, data)
            return target.phase == Player.Play and table.contains(player:getTableMark("perform_sacrament"), target.id)
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            local cards = table.filter(target:getCardIds("h"), function(id)
                return Fk:getCardById(id):getMark("@@perform_sacrament-inhand") > 0
            end)
            if #cards > 0 then
                room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, perform_sacrament.name)
                room:setPlayerMark(target, "perform_sacrament_lose", #cards)
            end
        end
    })
    local transcend_human = fk.CreateSkill {
        name = "transcend_human",
        tags = {
            Skill.Lord
        }
    }
    transcend_human:addEffect("active", {
        target_filter = Util.FalseFunc,
        card_filter = Util.FalseFunc,
        can_use = function(self, player)
            return table.any(Fk:currentRoom().alive_players, function(t)
                return t.kingdom == "ten_k" and t ~= player
            end) and player:usedSkillTimes(transcend_human.name, Player.HistoryPhase) < 1 and player:getMaxCards() > 0
        end,
        prompt = "transcend_human_prompt",
        on_use = function(self, room, cardUseEvent)
            local player = cardUseEvent.from
            local targets = table.filter(room:getOtherPlayers(player, true), function(t)
                return t.kingdom == "ten_k"
            end)
            local names = {}
            local choices = {}
            for _, name in ipairs(Fk:getAllCardNames("bt")) do
                table.insertIfNeed(names, name)
            end
            for _, t in ipairs(targets) do
                local name = room:askToChoice(t, {
                    choices = names,
                    skill_name = transcend_human.name,
                    prompt = "transcend_human_prompt_choice",
                    cancelable = false,
                })
                room:setPlayerMark(t, "@transcend_human", name)
                if player:canUse(Fk:cloneCard(name)) then
                    table.insertIfNeed(choices, name)
                end
            end
            if #choices > 0 then
                table.insertIfNeed(choices, "Cancel")
                local result = room:askToChoice(player, {
                    choices = choices,
                    skill_name = transcend_human.name,
                    prompt = "transcend_human_prompt_choose"
                })
                if result ~= "Cancel" then
                    local reduce = math.max(1, math.floor(player:getMaxCards() / 2))
                    room:askToUseVirtualCard(player, {
                        name = result,
                        skill_name = transcend_human.name,
                        prompt = "transcend_human_prompt_use:::" .. result,
                        cancelable = false,
                        extra_data = {
                            bypass_times = false,
                            extraUse = false,
                        }
                    })
                    room:addPlayerMark(player, MarkEnum.MinusMaxCards, reduce)
                end
            end
            for _, t in ipairs(targets) do
                room:setPlayerMark(t, "@transcend_human", 0)
            end
        end
    })
    hy_hijiri_byakuren:addSkill("unusual_buddhism")
    hy_hijiri_byakuren:addSkill("perform_sacrament")
    hy_hijiri_byakuren:addSkill("transcend_human")
    extension:loadSkillSkels { unusual_buddhism, perform_sacrament, transcend_human }
    Fk:loadTranslationTable {
        ["hy_hijiri_byakuren"] = "圣白莲",
        ["#hy_hijiri_byakuren"] = "慈航普度",
        ["designer:hy_hijiri_byakuren"] = "黑曜人形",
        ["illustrator:hy_hijiri_byakuren"] = "ハラクネ",
        ["cv:hy_hijiri_byakuren"] = "",

        ["unusual_buddhism"] = "异佛",
        [":unusual_buddhism"] = "其他角色使用牌指定你为目标后，若你的手牌数不大于手牌上限，你摸两张牌，然后将一张牌置于牌堆顶。",
        ["unusual_buddhism_prompt"] = "异佛：你须将一张牌置于牌堆顶",

        ["perform_sacrament"] = "行圣",
        [":perform_sacrament"] = "出牌阶段限一次，你可以将全部手牌<a href='temp_operation'>临时</a>交给一名其他角色直到其下个出牌阶段结束，若如此做，其下个出牌阶段结束时，你可以选择一项：1.视为使用其本阶段使用的基本牌与普通锦囊牌至多各一张；2.令你的手牌上限+X并摸一张牌（X为其本阶段因此法置入弃牌堆的牌数）。",
        ["perform_sacrament_prompt"] = "行圣：你可以将全部手牌交给一名角色",
        ["@@perform_sacrament-inhand"] = "行圣",
        ["perform_sacrament_prompt_choice"] = "行圣：你须选择一项",
        ["perform_sacrament_prompt_use"] = "行圣：你须使用%arg",
        ["perform_sacrament_draw"] = "摸一张牌，手牌上限+%arg",

        ["transcend_human"] = "超人",
        [":transcend_human"] = "主公技，出牌阶段限一次，你可以令其他天势力角色依次声明一个基本牌或普通锦囊牌的牌名，然后你可以令手牌上限减少一半（向下取整且至少为1）并视为使用其中一个声明的牌名。",
        ["transcend_human_prompt"] = "超人：你可以令其他天势力角色依次声明一个牌名",
        ["transcend_human_prompt_choice"] = "超人：你须声明一个牌名",
        ["transcend_human_prompt_choose"] = "超人：你可以选择一个牌名使用",
        ["transcend_human_prompt_use"] = "超人：你须使用%arg",
        ["@transcend_human"] = "超人",
    }
end
